package com.cloudpan.controller;

import com.cloudpan.common.R;
import com.cloudpan.service.SysFileInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @Author sc
 * @DATE 2024/1/26 14:59
 * @Description:
 * @Version 1.0
 */
@RestController
@RequestMapping("/sys/recyle")
@RequiredArgsConstructor
@Api(value = "文件回收站控制层", tags = "文件回收站控制层")
public class SysRecyleController {

    private final SysFileInfoService fileInfoService;

    @ApiOperation(value = "回收站文件还原,包含回收站文件彻底删除")
    @PutMapping("/{userId}/{fileId}")
    public R recycleFile(@PathVariable("userId") String fid,
                         @PathVariable("fileId") String fileId, Boolean isDelete){
        Boolean result =  fileInfoService.recycle(fid,fileId,isDelete);
        if (isDelete && result){
            return R.ok("回收站文件永久删除成功~");
        }
        return result?R.ok("回收站文件恢复成功,请查看"):R.failed("回收站文件恢复失败或未找到文件");
    }

    @ApiOperation(value = "文件删除(放入回收站或彻底删除)，true彻底删除，false回收站删除")
    @DeleteMapping(value = {"/delete/{userid}/{fileId}"})
    public R delete(@PathVariable("userid") String userid, @PathVariable("fileId") String fileId,Boolean isForce){
        //删除的文件放入回收站
        String fileName =  fileInfoService.delete(userid,fileId,isForce);
        //返回删除成功的文件
        if (isForce){
            return R.ok(fileName + "删除成功");
        }
        return R.ok(fileName + "删除成功,请在回收站中查看");
    }

}
